package com.zlzlib.libindex.decoration;

import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

import com.zlzlib.libindex.bean.BaseIndexBean;


/**
 * @Desc:分组头部悬浮可点击实例
 * @Copyright:
 * @DateTime: 2020/9/4 10:56
 * @Author zlz
 * @Version 1.0
 */
public class DemoHeadDecoration extends BaseHeadViewDecoration<BaseIndexBean> {

    private View head;
    private int selectPos = 0;
    private OnHeadClick onHeadClick;

    //设置头部点击事件响应
    public void setOnHeadClick(OnHeadClick onHeadClick) {
        this.onHeadClick = onHeadClick;
    }

    public DemoHeadDecoration(RecyclerView recyclerView, View head) {
        super(recyclerView);
        this.head = head;
        head.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != onHeadClick) onHeadClick.onClick(selectPos);
            }
        });
    }

    @Override
    protected View getDrawView(int position, RecyclerView parent) {
        selectPos = position;
        //获得头部
        BaseIndexBean bean = data.get(position);
        //设置head里面数据的变化
        return head;
    }

    @Override
    protected int getOutRectHeight() {
        return 0;
    }

    public interface OnHeadClick {
        void onClick(int pos);
    }
}
